package com.lxh.lxhcrm.controller.productManagement;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.*;
import com.lxh.lxhcrm.model.service.CaigouService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/caigou")
public class  CaigouController {
    @Resource
    CaigouService caigouService;
    /*
     * 查询
     * */
    //申请采购表列表查询
    @RequestMapping("/appcai-list")
    public Map<String,Object> appcaiList(Integer currPage, Integer pageSize,String searchText,Integer selectModel,Integer judge){
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> map=new HashMap<>();
        List<AppCai> appcai=caigouService.findAppCai(searchText,selectModel,judge);
        map.put("data",appcai);
        map.put("total",page.getTotal());
        return map;
    }
    //无分页查询申请采购表
    @RequestMapping("/all-appcai")
    public List<AppCai> allAppCai(){
        List<AppCai> appCais=caigouService.allAppCai();
        return appCais;
    }
    //采购表列表查询
    @RequestMapping("/caigou-list")
    public Map<String,Object> caigouList(Integer currPage, Integer pageSize,String searchText,Integer selectModel,Integer judge){
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> map=new HashMap<>();
        List<Caigou> caigou=caigouService.findCaigou(searchText,selectModel,judge);
        map.put("data",caigou);
        map.put("total",page.getTotal());
        return map;
    }
    //无分页查询采购表
    @RequestMapping("/all-caigou")
    public List<Caigou> allCaigou(){
        List<Caigou> caigous=caigouService.allCaigou();
        return caigous;
    }
    //支付方式查询
    @RequestMapping("/pay-list")
    public List<PayWey> payWeyList(){
        List<PayWey> payWey=caigouService.findPayWey();
        return payWey;
    }
    //交货方式查询
    @RequestMapping("/delivery-list")
    public List<DeliveryType> deliveryTypeList(){
        List<DeliveryType> deliveryType=caigouService.findDeliveryType();
        return deliveryType;
    }
    //发票类别查询
    @RequestMapping("/invoice-list")
    public List<InvoiceType> invoiceTypeList(){
        List<InvoiceType> invoiceType=caigouService.findInvoiceType();
        return invoiceType;
    }
    //付款约定查询
    @RequestMapping("/appoint-list")
    public List<AppointPay> appointPayList() {
        List<AppointPay> appointPay=caigouService.findAppointPay();
        return appointPay;
    }
    //供货商查询
    @RequestMapping("/supplier-list")
    public List<Supplier> supplierList(){
        List<Supplier> supplier=caigouService.findSupplier();
        return supplier;
    }
    //查询此用户是否具备审核功能
    @RequestMapping("/findDuty")
    public boolean findDuty(Integer empId){
        return caigouService.findDuty(empId);
    }
    /*
     * 新增
     * */
    //供货商新增
    @RequestMapping("/add-supplier")
    public void addSupplier(@RequestBody Supplier supplier){
        caigouService.addSupplier(supplier);
    }
    //添加申请采购抬头表
    @RequestMapping("/add_appcai")
    public void addAppCai(@RequestBody AppCai appCai) {
        caigouService.addAppCai(appCai);
    }
    //添加申请采购详情表
    @RequestMapping("/add_appdetail")
    public void addAppDetail(@RequestBody AppDetail appDetail){
        caigouService.addAppDetail(appDetail);
    }
    //添加采购表
    @RequestMapping("/add_caigou")
    public void addCaigou(@RequestBody Caigou caigou){ caigouService.addCaigou(caigou);}
    /*
     * 修改
     * */
    //修改申请采购表状态
    @RequestMapping("/change-appcaistate")
    public void changeAppCaiState(Integer judge,Integer appCaiId){caigouService.changeAppCaiState(judge,appCaiId);}
    //修改采购表状态
    @RequestMapping("/change-caistate")
    public void changeCaiState(Integer judge,Integer caiId){caigouService.changeCaiState(judge,caiId);}
    //修改采购表
    @RequestMapping("update-cai")
    public void updateCai(Integer empId, Integer deliveryId, Integer invoiceId, Integer payId, Integer appointId, Date deliveryDate, String caddDel, Integer caiId){
        caigouService.updateCai(empId,deliveryId,invoiceId,payId,appointId,deliveryDate,caddDel,caiId);
    }
}
